import * as actionTypes from "./constants"

import {
  getTopBanners,
  getCoverList,
  getNewAlbum,
  getRankingList,
  getArtistList
} from '@/services/recommend'

// 轮播图
const changeBannerAction = res => ({
  type: actionTypes.CHANGE_TOP_BANNER,
  banners: res.banners
})

export const getTopBannerAction = () => {
  return dispatch => {
    getTopBanners().then(res => {
      dispatch(changeBannerAction(res))
    })
  }
}

// 热推荐
export const changeCoverListAction = res => ({
  type: actionTypes.CHANGE_COVER_LIST,
  cover: res.result
})

export const getRcmCoverAction = (obj) => {
  return dispatch => {
    getCoverList(obj).then(res => {
      dispatch(changeCoverListAction(res))
    })
  }
}

// 新碟上架
export const changeNewAlbumAction = res => ({
  type: actionTypes.CHANGE_NEW_ALBUM,
  album: res.albums
})

export const getRcmNewAlbumAction = (obj) => {
  return dispatch => {
    getNewAlbum(obj).then(res => {
      dispatch(changeNewAlbumAction(res))
    })
  }
}

// 排行
export const changeRankingList1Action = res => ({
  type: actionTypes.CHANGE_RANK_LIST1,
  rank: res.playlist
})

export const changeRankingList2Action = res => ({
  type: actionTypes.CHANGE_RANK_LIST2,
  rank: res.playlist
})

export const changeRankingList3Action = res => ({
  type: actionTypes.CHANGE_RANK_LIST3,
  rank: res.playlist
})

export const getRankingListAction = obj => {
  return dispatch => {
    getRankingList(obj).then(res => {
      switch(obj.idx) {
        case 0:
          dispatch(changeRankingList1Action(res))
          break
        case 2:
          dispatch(changeRankingList2Action(res))
          break
        case 3:
          dispatch(changeRankingList3Action(res))
          break
        default:
          console.log("暂无匹配数据")
      }
    })
  }
}

// 入驻歌手
export const changeInSingerAction = res => ({
  type: actionTypes.CHANGE_IN_SINGER,
  artists: res.artists
})

export const getInSinger = obj => {
  return dispatch => {
    getArtistList(obj).then(res => {
      dispatch(changeInSingerAction(res))
    })
  }
}

